package com.taobao.txc.parser.b.c;

import com.a.a.a.a.a.f.c.i;
import com.a.a.a.a.a.f.j;
import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.parser.struct.TxcTable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.commons.lang.StringUtils;

public class e
  extends a
  implements com.taobao.txc.parser.b.a.c
{
  private static final LoggerWrap i = LoggerInit.logger;
  
  public e(k paramk)
  {
    super(paramk);
  }
  
  private com.a.a.a.a.c.c.d l()
  {
    return (com.a.a.a.a.c.c.d)((k)j()).e();
  }
  
  public void a(com.a.a.a.a.c.c.d paramd) {}
  
  public String k()
  {
    com.a.a.a.a.c.c.d locald = l();
    StringBuilder localStringBuilder = h();
    localStringBuilder.append("INSERT ");
    switch (g.a[locald.e().ordinal()])
    {
    case 1: 
      localStringBuilder.append("DELAYED ");
      break;
    case 2: 
      localStringBuilder.append("HIGH_PRIORITY ");
      break;
    case 3: 
      localStringBuilder.append("LOW_PRIORITY ");
      break;
    case 4: 
      break;
    default: 
      throw new IllegalArgumentException("unknown mode for INSERT: " + locald.e());
    }
    if (locald.f()) {
      localStringBuilder.append("IGNORE ");
    }
    localStringBuilder.append("INTO ");
    localStringBuilder.append(j().b());
    localStringBuilder.append(' ');
    List localList1 = locald.b();
    if ((localList1 != null) && (!localList1.isEmpty()))
    {
      localStringBuilder.append('(');
      a(localList1);
      localStringBuilder.append(") ");
    }
    com.a.a.a.a.a.e.c localc = locald.d();
    if (localc == null)
    {
      localStringBuilder.append("VALUES ");
      localList2 = locald.c();
      if ((localList2 == null) || (localList2.isEmpty())) {
        throw new IllegalArgumentException("at least one row for INSERT");
      }
      a(localList2, localList1, localStringBuilder);
    }
    else
    {
      localc.a(this);
    }
    List localList2 = locald.g();
    if ((localList2 != null) && (!localList2.isEmpty()))
    {
      localStringBuilder.append(" ON DUPLICATE KEY UPDATE ");
      int j = 1;
      Iterator localIterator = localList2.iterator();
      while (localIterator.hasNext())
      {
        com.a.a.a.c.b localb = (com.a.a.a.c.b)localIterator.next();
        if (j != 0) {
          j = 0;
        } else {
          localStringBuilder.append(", ");
        }
        ((com.a.a.a.a.a.f.d)localb.a()).a(this);
        localStringBuilder.append(" = ");
        ((com.a.a.a.a.a.c)localb.b()).a(this);
      }
    }
    return localStringBuilder.toString();
  }
  
  public String d(com.taobao.txc.resourcemanager.b.a.d paramd)
  {
    com.a.a.a.a.c.c.d locald = l();
    List localList1 = locald.c();
    List localList2 = locald.b();
    if (localList2 == null) {
      throw new SQLException("INSERT SQL [" + locald + "] without column names is not supported!");
    }
    if ((localList1 == null) || (localList1.isEmpty())) {
      throw new IllegalArgumentException("at least one row for INSERT");
    }
    String str = null;
    if (f().a(new f(this, localList2))) {
      try
      {
        str = b(localList1, localList2, paramd);
      }
      catch (Exception localException)
      {
        i.a(com.taobao.txc.common.b.b.aS, localException);
        str = a(localList1, localList2, paramd);
      }
    } else {
      str = a(localList1, localList2, paramd);
    }
    if (i.c()) {
      i.debug("whereSqlAppender:" + str);
    }
    return String.format(" WHERE %s", new Object[] { str });
  }
  
  public TxcTable b(com.taobao.txc.resourcemanager.b.a.d paramd)
  {
    a(i());
    return c();
  }
  
  public TxcTable c(com.taobao.txc.resourcemanager.b.a.d paramd)
  {
    if (i.c())
    {
      localObject = f();
      Map localMap = ((com.taobao.txc.parser.struct.k)localObject).d();
      Iterator localIterator = localMap.entrySet().iterator();
      while (localIterator.hasNext())
      {
        Map.Entry localEntry = (Map.Entry)localIterator.next();
        i.debug(" [" + (String)localEntry.getKey() + "--->" + localEntry.getValue() + "] ");
      }
    }
    Object localObject = g() + d(paramd);
    b(b(paramd, (String)localObject));
    return d();
  }
  
  private void a(List<com.a.a.a.a.a.f.d> paramList, j paramj, int paramInt, StringBuilder paramStringBuilder)
  {
    int j = 1;
    List localList = paramj.b();
    for (int k = 0; k < localList.size(); k++)
    {
      String str = ((com.a.a.a.a.a.f.d)paramList.get(k)).f();
      com.taobao.txc.parser.struct.k localk = f();
      com.taobao.txc.parser.struct.f localf = localk.c(str);
      if (localf.a())
      {
        Object localObject1 = null;
        com.a.a.a.a.a locala = (com.a.a.a.a.a)localList.get(k);
        Object localObject2;
        if ((locala instanceof com.a.a.a.a.a.f.c.h))
        {
          localObject2 = (com.a.a.a.a.a.f.c.h)locala;
          localObject1 = ((com.a.a.a.a.a.f.c.h)localObject2).b();
        }
        else if ((locala instanceof i))
        {
          localObject2 = (i)locala;
          localObject1 = ((i)localObject2).c();
        }
        else if ((locala instanceof com.a.a.a.a.a.f.g))
        {
          localObject2 = (com.a.a.a.a.a.f.g)locala;
          int m = ((com.a.a.a.a.a.f.g)localObject2).b();
          localObject1 = a(m, paramInt);
        }
        if (localObject1 != null)
        {
          if (j != 0) {
            j = 0;
          } else {
            paramStringBuilder.append(" AND ");
          }
          l.a(str, localObject1, paramStringBuilder);
        }
      }
    }
  }
  
  private String a(List<j> paramList, List<com.a.a.a.a.a.f.d> paramList1, com.taobao.txc.resourcemanager.b.a.d paramd)
  {
    StringBuilder localStringBuilder = h();
    com.taobao.txc.parser.struct.f localf = f().e();
    if (localf == null) {
      throw new IllegalArgumentException("no auto increase column.");
    }
    ResultSet localResultSet = null;
    try
    {
      localResultSet = paramd.f().getGeneratedKeys();
    }
    catch (SQLException localSQLException)
    {
      if (localSQLException.getSQLState().equalsIgnoreCase("S1009")) {
        localResultSet = paramd.f().executeQuery("SELECT LAST_INSERT_ID()");
      }
    }
    if (localResultSet != null)
    {
      int j = 1;
      while (localResultSet.next())
      {
        if (j != 0) {
          j = 0;
        } else {
          localStringBuilder.append(" OR ");
        }
        localStringBuilder.append(localf.b());
        localStringBuilder.append("=");
        localStringBuilder.append(localResultSet.getObject(1));
      }
      localResultSet.close();
    }
    else
    {
      a(localStringBuilder, paramList, paramList1);
    }
    return localStringBuilder.toString();
  }
  
  private void a(StringBuilder paramStringBuilder, List<j> paramList, List<com.a.a.a.a.a.f.d> paramList1)
  {
    int j = 1;
    int k = b();
    Object localObject;
    if (k == 0)
    {
      localObject = paramList.iterator();
      while (((Iterator)localObject).hasNext())
      {
        j localj = (j)((Iterator)localObject).next();
        if ((localj != null) && (!localj.b().isEmpty()))
        {
          if (j != 0) {
            j = 0;
          } else {
            paramStringBuilder.append(" OR ");
          }
          a(paramList1, localj, 1, paramStringBuilder);
        }
      }
    }
    else
    {
      localObject = (j)paramList.get(0);
      for (int m = 1; m <= k; m++)
      {
        if (j != 0) {
          j = 0;
        } else {
          paramStringBuilder.append(" OR ");
        }
        a(paramList1, (j)localObject, m, paramStringBuilder);
      }
    }
  }
  
  private void a(List<j> paramList, List<com.a.a.a.a.a.f.d> paramList1, StringBuilder paramStringBuilder)
  {
    int j = b();
    Object localObject;
    if (j == 0)
    {
      Iterator localIterator = paramList.iterator();
      while (localIterator.hasNext())
      {
        j localj1 = (j)localIterator.next();
        paramStringBuilder.append('(');
        localObject = localj1.b();
        int n = 1;
        for (int i1 = 0; i1 < ((List)localObject).size(); i1++)
        {
          com.a.a.a.a.a locala1 = (com.a.a.a.a.a)((List)localObject).get(i1);
          if (n != 0) {
            n = 0;
          } else {
            paramStringBuilder.append(", ");
          }
          locala1.a(this);
        }
        paramStringBuilder.append(')');
      }
    }
    else
    {
      int k = 1;
      for (int m = 1; m <= j; m++)
      {
        if (k != 0) {
          k = 0;
        } else {
          paramStringBuilder.append(", ");
        }
        localObject = paramList.iterator();
        while (((Iterator)localObject).hasNext())
        {
          j localj2 = (j)((Iterator)localObject).next();
          paramStringBuilder.append('(');
          List localList = localj2.b();
          int i2 = 1;
          for (int i3 = 0; i3 < localList.size(); i3++)
          {
            com.a.a.a.a.a locala2 = (com.a.a.a.a.a)localList.get(i3);
            if (i2 != 0) {
              i2 = 0;
            } else {
              paramStringBuilder.append(", ");
            }
            if ((locala2 instanceof com.a.a.a.a.a.f.g))
            {
              com.a.a.a.a.a.f.g localg = (com.a.a.a.a.a.f.g)locala2;
              int i4 = localg.b();
              paramStringBuilder.append(a(i4, m));
            }
            else
            {
              locala2.a(this);
            }
          }
          paramStringBuilder.append(')');
        }
      }
    }
  }
  
  private String b(List<j> paramList, List<com.a.a.a.a.a.f.d> paramList1, com.taobao.txc.resourcemanager.b.a.d paramd)
  {
    StringBuilder localStringBuilder = h();
    int j = b();
    int k = 1;
    int m = 0;
    Object localObject1 = null;
    Object localObject2;
    j localj;
    Object localObject3;
    Object localObject4;
    Object localObject5;
    Object localObject6;
    String str2;
    Object localObject7;
    com.a.a.a.a.a locala;
    if (j == 0)
    {
      localObject2 = paramList.iterator();
      while (((Iterator)localObject2).hasNext())
      {
        localj = (j)((Iterator)localObject2).next();
        if ((localj != null) && (!localj.b().isEmpty()))
        {
          List localList1 = localj.b();
          for (int i2 = 0; i2 < localList1.size(); i2++)
          {
            String str1 = ((com.a.a.a.a.a.f.d)paramList1.get(i2)).f();
            localObject3 = f();
            localObject4 = ((com.taobao.txc.parser.struct.k)localObject3).f();
            localObject5 = ((com.taobao.txc.parser.struct.k)localObject3).c(str1);
            if (localObject5 == null) {
              localObject5 = (com.taobao.txc.parser.struct.f)((com.taobao.txc.parser.struct.k)localObject3).c().get(str1.toLowerCase());
            }
            if (((com.taobao.txc.parser.struct.f)localObject5).a())
            {
              localObject6 = ((com.taobao.txc.parser.struct.k)localObject3).b();
              str2 = ((com.taobao.txc.parser.struct.f)localObject5).b().toUpperCase();
              if (((Map)localObject4).get(str2) != null)
              {
                localObject7 = null;
                locala = (com.a.a.a.a.a)localList1.get(i2);
                Object localObject8;
                if ((locala instanceof com.a.a.a.a.a.f.c.h))
                {
                  localObject8 = (com.a.a.a.a.a.f.c.h)locala;
                  localObject7 = ((com.a.a.a.a.a.f.c.h)localObject8).b();
                  if ((localObject7 != null) && (localObject7.equals(Integer.valueOf(0))))
                  {
                    String str4 = ((com.taobao.txc.parser.struct.f)localObject5).e();
                    if ((str4 != null) && ((str4.charAt(0) == 'Y') || (str4.charAt(0) == 'y')))
                    {
                      localObject7 = null;
                      m = 1;
                      localObject1 = str2;
                    }
                  }
                }
                else if ((locala instanceof i))
                {
                  localObject8 = (i)locala;
                  localObject7 = ((i)localObject8).c();
                }
                else if ((locala instanceof com.a.a.a.a.a.f.c.g))
                {
                  localObject7 = h.a();
                  int i4 = ((com.taobao.txc.parser.struct.f)localObject5).c();
                  switch (i4)
                  {
                  case -6: 
                  case -5: 
                  case 2: 
                  case 4: 
                  case 5: 
                    localObject7 = null;
                    m = 1;
                    localObject1 = str2;
                  }
                }
                else if (((locala instanceof com.a.a.a.a.a.f.d)) && (((com.a.a.a.a.a.f.d)locala).b()))
                {
                  m = 1;
                  localObject1 = str2;
                }
                else
                {
                  throw new SQLException("type of pk is:" + locala.toString());
                }
                str1 = String.format("%s.%s", new Object[] { localObject6, str1 });
                if (localObject7 != null)
                {
                  if (k != 0) {
                    k = 0;
                  } else {
                    localStringBuilder.append(" OR ");
                  }
                  l.a(str1, localObject7, localStringBuilder);
                }
              }
            }
          }
        }
      }
    }
    else
    {
      localObject2 = paramList.iterator();
      while (((Iterator)localObject2).hasNext())
      {
        localj = (j)((Iterator)localObject2).next();
        for (int i1 = 1; i1 <= j; i1++)
        {
          List localList2 = localj.b();
          for (int i3 = 0; i3 < localList2.size(); i3++)
          {
            localObject3 = ((com.a.a.a.a.a.f.d)paramList1.get(i3)).f();
            localObject4 = f();
            localObject5 = ((com.taobao.txc.parser.struct.k)localObject4).f();
            localObject6 = ((com.taobao.txc.parser.struct.k)localObject4).c((String)localObject3);
            if (((com.taobao.txc.parser.struct.f)localObject6).a())
            {
              str2 = ((com.taobao.txc.parser.struct.f)localObject6).b().toUpperCase();
              if (((Map)localObject5).get(str2) != null)
              {
                localObject7 = null;
                locala = (com.a.a.a.a.a)localList2.get(i3);
                Object localObject9;
                if ((locala instanceof com.a.a.a.a.a.f.c.h))
                {
                  localObject9 = (com.a.a.a.a.a.f.c.h)locala;
                  localObject7 = ((com.a.a.a.a.a.f.c.h)localObject9).b();
                }
                else if ((locala instanceof i))
                {
                  localObject9 = (i)locala;
                  localObject7 = ((i)localObject9).c();
                }
                else if ((locala instanceof com.a.a.a.a.a.f.c.g))
                {
                  localObject7 = h.a();
                }
                else if (((locala instanceof com.a.a.a.a.a.f.d)) && (((com.a.a.a.a.a.f.d)locala).b()))
                {
                  m = 1;
                  localObject1 = str2;
                }
                else if ((locala instanceof com.a.a.a.a.a.f.g))
                {
                  localObject9 = (com.a.a.a.a.a.f.g)locala;
                  int i6 = ((com.a.a.a.a.a.f.g)localObject9).b();
                  localObject7 = a(i6, i1);
                }
                if ((localObject7 != null) && (localObject7 == h.a()))
                {
                  int i5 = ((com.taobao.txc.parser.struct.f)localObject6).c();
                  switch (i5)
                  {
                  case -6: 
                  case -5: 
                  case 2: 
                  case 4: 
                  case 5: 
                    localObject7 = null;
                    m = 1;
                    localObject1 = str2;
                  }
                }
                else if ((localObject7 != null) && ((localObject7 instanceof Number)) && (((Number)localObject7).longValue() == 0L))
                {
                  String str3 = ((com.taobao.txc.parser.struct.f)localObject6).e();
                  if ((str3 != null) && ((str3.charAt(0) == 'Y') || (str3.charAt(0) == 'y')))
                  {
                    localObject7 = null;
                    m = 1;
                    localObject1 = str2;
                  }
                }
                if (localObject7 != null)
                {
                  if (k != 0) {
                    k = 0;
                  } else {
                    localStringBuilder.append(" OR ");
                  }
                  l.a((String)localObject3, localObject7, localStringBuilder);
                }
              }
            }
          }
        }
      }
    }
    if (m != 0)
    {
      localObject2 = paramd.getGeneratedKeys();
      if ((localObject2 != null) && (!StringUtils.isEmpty(localObject1)))
      {
        for (int n = 0; ((ResultSet)localObject2).next(); n++)
        {
          if (k != 0) {
            k = 0;
          } else {
            localStringBuilder.append(" OR ");
          }
          localStringBuilder.append(localObject1);
          localStringBuilder.append("=");
          localStringBuilder.append(((ResultSet)localObject2).getObject(1));
        }
        ((ResultSet)localObject2).close();
        if (n == 0) {
          throw new IllegalArgumentException("pk is not generated id " + localObject1);
        }
      }
      else
      {
        throw new IllegalArgumentException("pk is not generated id or pk column is invalid " + localObject1);
      }
    }
    return localStringBuilder.toString();
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.parser.b.c.e
 * JD-Core Version:    0.7.0.1
 */